package com.hetao.xx.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.hetao.xx.game.Game;
import com.hetao.xx.game.model.User;
import com.hetao.xx.Global;
import com.hetao.xx.R;
import com.hetao.xx.service.IntentManager;
import com.hetao.xx.service.MakeWorldService;
import com.hetao.xx.service.UserManager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.hetao.xx.service.IntentManager.StartClose;


public class NewActivity extends AppCompatActivity {

    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.new_name)
    EditText nickNameEdit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new);
        ButterKnife.bind(this);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setTitle("输入昵称");
    }

    @SuppressLint("NonConstantResourceId")
    @OnClick(R.id.new_create)
    public void onOkClick(View v) {
        String nickName = nickNameEdit.getText().toString();
        if(UserManager.checkUser(nickName)) {
            User user = new MakeWorldService().makeUserRole(nickName);
            UserManager.saveUserInfo(user.info);

            Global.getInstant().setUser(user);

            IntentManager.toMain(this);
            setResult(StartClose);
            finish();
        }
    }
}
